package com.hunliji.monitor.web.controller.app;

import com.hunliji.common.response.PageData;
import com.hunliji.common.response.ResponseData;
import com.hunliji.monitor.service.api.model.param.QueryTableChangeOrderParam;
import com.hunliji.monitor.web.facade.TableChangeOrderFacade;
import com.hunliji.monitor.web.filter.GeneralContext;
import com.hunliji.monitor.web.filter.auth.NeedAuth;
import com.hunliji.monitor.web.model.param.AddTableChangeOrderParam;
import com.hunliji.monitor.web.model.vo.BusinessChangeOrderDetailVO;
import com.hunliji.monitor.web.model.vo.ChangeOrderDetailVO;
import com.hunliji.monitor.web.model.vo.ChangeOrderVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 变更单
 * @author wuchen
 */
@RestController
@RequestMapping("/appApi/tableChangeOrder")
public class TableChangeOrderController {
    @Resource
    private TableChangeOrderFacade tableChangeOrderFacade;
    /**
     * 添加变更单
     * @param addTableChangeOrderParam
     * @return
     */
    @NeedAuth
    @PostMapping("/add")
    public ResponseData add(@RequestBody AddTableChangeOrderParam addTableChangeOrderParam){
        addTableChangeOrderParam.setUserId(GeneralContext.getAdmin().getId());
        tableChangeOrderFacade.add(addTableChangeOrderParam);
        return ResponseData.success(null);
    }

    /**
     * 撤回变更单
     * @param id
     * @return
     */
    @NeedAuth
    @PostMapping("/cancel")
    public ResponseData cancel(@RequestParam("id") Long id){
        tableChangeOrderFacade.cancel(id,GeneralContext.getAdmin().getId());
        return ResponseData.success(null);
    }

    /**
     * 分页查询-我的变更单
     * @param queryTableChangeOrderParam
     * @return
     */
    @NeedAuth
    @PostMapping("/queryPage")
    public ResponseData<PageData<ChangeOrderVO>> queryPage(@RequestBody QueryTableChangeOrderParam queryTableChangeOrderParam){
        queryTableChangeOrderParam.setUserId(GeneralContext.getAdmin().getId());
        return ResponseData.success(tableChangeOrderFacade.queryPage(queryTableChangeOrderParam));
    }

    @PostMapping("/queryPageIgnoreLogin")
    public ResponseData<PageData<ChangeOrderVO>> queryPageIgnoreLogin(@RequestBody QueryTableChangeOrderParam queryTableChangeOrderParam){
        queryTableChangeOrderParam.setUserId(GeneralContext.getAdmin().getId());
        return ResponseData.success(tableChangeOrderFacade.queryPage(queryTableChangeOrderParam));
    }

    /**
     * 根据id查询详情
     * @param id 确认单id
     * @return
     */
    @NeedAuth
    @GetMapping("/queryDetailById")
    public ResponseData<ChangeOrderDetailVO> queryDetailById(@RequestParam("id") Long id){
        return ResponseData.success(tableChangeOrderFacade.queryById(id,GeneralContext.getAdmin().getId()));
    }

    /**
     * 根据id查询详情
     * @param id 确认单id
     * @return
     */
    @GetMapping("/queryDetailByIdIgnoreLogin")
    public ResponseData<ChangeOrderDetailVO> queryDetailByIdIgnoreLogin(@RequestParam("id") Long id){
        return ResponseData.success(tableChangeOrderFacade.queryById(id,null));
    }

}
